﻿using IDAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class D_Goods : IGoods
    {
        public void Add(Goods item)
        {
            CakeEntities db = new CakeEntities();
            db.Goods.Add(item);
            db.SaveChanges();
        }

        public void Delete(int id)
        {
            CakeEntities db = new CakeEntities();
            db.Goods.Remove(db.Goods.Find(id));
            db.SaveChanges();
        }

        public Goods FindById(int id)
        {
            CakeEntities db = new CakeEntities();
            return db.Goods.Find(id);
        }

        public List<Goods> GetAll()
        {
            CakeEntities db = new CakeEntities();
            return db.Goods.ToList();
        }

        public void Updata(int id, Goods item)
        {
            CakeEntities db = new CakeEntities();
            var data=db.Goods.Find(id);
            if (data != null)
            {
                data.GoodsName=item.GoodsName;
                data.Cover=item.Cover;
                data.GoodsHeat=item.GoodsHeat;
                data.Material=item.Material;
                data.Packing=item.Packing;
                data.Explan=item.Explan;
                data.Gift=item.Gift;
                data.Delivery=item.Delivery;
                data.CategoryId=item.CategoryId;
                data.TastId=item.TastId;
                data.LayerId=item.LayerId;
                data.ShapeId=item.ShapeId;
                db.SaveChanges();
            }
           
        }
    }
}
